import { reqSearch, reqSearchHistory, reqSearchDelete } from "../../api/search"

// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchinput:'',
    records:[],
    model:''
  },

  onLoad(opt){
    console.log(opt)
    const type = opt.type
    if(type){
      this.setData({
        model:1
      })
    }
  },

  onShow(){
    this.gethistory()
  },

  async gethistory(){
    const {data} = await reqSearchHistory()
    // console.log(data)

    this.setData({
      records:data
    })
  },

  async deletehistory(){
    const {data} = await reqSearchDelete()
    this.setData({
      records:[]
    })
  },

  navigateToSearchResult:function(){
    const record = this.data.searchinput
    // console.log(record)
    const model = this.data.model
    if(model == 1){
    wx.navigateTo({
      url: `/pages/searchresult/searchresult?record=${record}&type=${model}`
    });
    }else{
      wx.navigateTo({
        url: `/pages/searchresult/searchresult?record=${record}`,
      })
    }
  }
})